package com.crr.mall.product.app;

import java.util.Arrays;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import cn.hutool.core.bean.BeanUtil;
import com.crr.mall.common.bean.ResultBean;
import com.crr.mall.common.utils.BaseController;
import com.crr.mall.product.query.AttrQuery;
import com.crr.mall.product.vo.AttrVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.crr.mall.product.entity.AttrEntity;
import com.crr.mall.product.service.AttrService;
import com.crr.mall.common.utils.PageUtils;
import com.crr.mall.common.utils.R;



/**
 * 商品属性
 *
 * @author chenrenren
 * @email chenrenren@gmail.com
 * @date 2024-11-22 17:42:37
 */
@RestController
@RequestMapping("product/attr")
public class AttrController extends BaseController {
    @Autowired
    private AttrService attrService;

    /**
     * 列表
     */
    @PostMapping("/list")
   // @RequiresPermissions("product:attr:list")
    public ResultBean list(@RequestBody AttrQuery attrQuery){
        PageUtils page = attrService.queryByCondition(BeanUtil.beanToMap(attrQuery));
        return success("规格属性列表",page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
   // @RequiresPermissions("product:attr:info")
    public R info(@PathVariable("attrId") Long attrId){
		AttrEntity attr = attrService.getById(attrId);
        return R.ok().put("attr", attr);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
   // @RequiresPermissions("product:attr:save")
    public ResultBean save(@RequestBody AttrVO attr){
        int i = attrService.saveAttr(attr);
        return saveResult(i);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   // @RequiresPermissions("product:attr:update")
    public ResultBean update(@RequestBody AttrVO attr){
        int i = attrService.updateAttr(attr);

        return updateResult(i);
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
   // @RequiresPermissions("product:attr:delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
